package com.itheima.ThreadPrac7;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Callable;

public class mythread7 implements Callable<Integer>{
    ArrayList<Integer> list=new ArrayList<>();

    public mythread7(ArrayList<Integer> list) {
        this.list = list;
    }


    @Override
    public Integer call() throws Exception
    {
        ArrayList<Integer> boxlist = new ArrayList<>();
        double SUM = 0;
        while (true) {
            synchronized (mythread7.class) {
                if (list.size() == 0) {//还要获取该集合内的最高奖项,以及输出总金额
                    int maxnum = Collections.max(boxlist);
                    System.out.println(Thread.currentThread().getName() + boxlist + ",其中最高的金额为" + maxnum + "总金额为" + SUM + "元。");
                    break;
                } else {
                    Collections.shuffle(list);
                    int prize = list.remove(0);
                    SUM += prize;
                    boxlist.add(prize);
                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }
        if (boxlist.size() == 0)
            return null;
        else
            return Collections.max(boxlist);
    }
}
